<template>
  <a-dropdown>
    <div class="header-avatar" style="cursor: pointer">
<!--      <a-avatar class="avatar" size="small" shape="circle" :src="user.avatar"/>-->
      <a-icon  class="avatar" type="smile" theme="twoTone" />
      <span class="name">{{user.username}} ({{roleName(user.role)}})</span>
    </div>
    <a-menu :class="['avatar-menu']" slot="overlay">
<!--      <a-menu-item>-->
<!--        <a-icon type="user" />-->
<!--        <span>个人中心</span>-->
<!--      </a-menu-item>-->
<!--      <a-menu-item>-->
<!--        <a-icon type="setting" />-->
<!--        <span>修改密码</span>-->
<!--      </a-menu-item>-->
<!--      <a-menu-divider />-->
      <a-menu-item @click="logout">
        <a-icon style="margin-right: 8px;" type="poweroff" />
        <span>退出登录</span>
      </a-menu-item>
    </a-menu>
  </a-dropdown>
</template>

<script>
import {mapGetters} from 'vuex'
import {logout} from '@/services/user'

export default {
  name: 'HeaderAvatar',
  computed: {
    ...mapGetters('account', ['user']),
  },
  methods: {
    logout() {
      logout()
      this.$router.push('/login')
    },
    roleName(role) {
      switch (role) {
        case 'sys_admin':
          return '系统管理员'
        case 'super_admin':
          return '校级领导'
        case 'org_admin':
          return '学院领导'
        case 'admin':
          return '教研室主任'
        case 'teacher':
          return '普通教师'
      }
    },
  }
}
</script>

<style lang="less">
  .header-avatar{
    display: inline-flex;
    .avatar, .name{
      align-self: center;
    }
    .avatar{
      margin-right: 8px;
    }
    .name{
      font-weight: 500;
    }
  }
  .avatar-menu{
    width: 150px;
  }

</style>
